$(document).ready(function (){
	sessionUrl();
	showsession();
	
	checkmsg();
	showtime = getNowFormatDate();
	startnum = $('.startnum').text();
	startnum = showstreet(startnum,showtime);
	checklinks();
	//点击展示
	$('.submit').click(function(){
		$('.submitMenu').slideDown('fast');
		$('.closeBar').slideDown('fast');
	});	
	//点击关闭
	$('.closeBar').click(function(){
		$('.submitMenu').slideUp('fast');
		$('.closeBar').slideUp('fast');
	});
	//点击加载更多
	$('.showmorepost').click(function(){
		//showMistAndWait();
		startnum = $('.startnum').text();
		console.log(startnum);
		showstreet(startnum,showtime);
	});
	//回到顶点
	$('.backToTop').click(function(){
		$("body,html").animate({scrollTop:0},300);
	});

});

//展示street中的帖子
function showstreet(startnum,showtime){
	$.ajax({
		type:'post',
		url:'../actions/c2cAction.php',
		data:	{
			act		 :	'getpostlist',
			startnum : 	startnum,
			showtime :	showtime
		}, 
		async: true,
		beforeSend:function(){
			showMistAndWait();
			//这里是开始执行方法，显示效果，效果自己写
		},
		success:function(data){
			//console.log(data);
			if(data){		
				$('.all_posts').append(data);
				show_1stpic_or_maxheight();
			}else{
				alert('没有更多内容啦');
			}
			hideMistAndWait();
		}
	}); 
	$('.startnum').text(Number(startnum) + 8);
}

//判断内容是否有图片，
//如果有图片：仅展示第一张图，文字不做展示；
//如果没有图片：展示文字，max-height为60px;
function show_1stpic_or_maxheight(){
	$('.postcontent').each(function(){
		var imgs = $(this).find('img');
		imglength = imgs.length;
		if(imglength > 0){
			var showimg = document.getElementById(imgs[0].id);
			$(this).html(showimg);
		}else{
			$(this).css('max-height','60px');
		}
	});
}